package com.fw.mediasession.media.mediasession;

import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media.MediaBrowserServiceCompat;

import com.fw.mediasession.media.player.ExoMediaPlayerUSB;
import com.zy.untils.AppExecutors;
import com.zy.untils.MyLog;
import com.zy.untils.MyNotificationUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class MyMediaBrowserService extends MediaBrowserServiceCompat  {
    private static final String MY_MEDIA_ROOT_ID = "media_root_id";
    private static final String MY_EMPTY_MEDIA_ROOT_ID = "empty_root_id";
    private String TAG = "MyMediaBrowserService: ";
    private MediaSessionCompat mediaSession;
    private PlaybackStateCompat.Builder stateBuilder;
    @Inject
    public ExoMediaPlayerUSB mediaPlayerUSB;
//    public MediaPlayer2USB mediaPlayerUSB;
    @Inject
    AppExecutors appExecutors;
    private MyMediaSessionManager myMediaSessionManager;

    @Override
    public void onCreate() {
        super.onCreate();
        MyNotificationUtils.setNotification(this);
        mediaSession = new MediaSessionCompat(this,"MyMediaBrowserService");
        myMediaSessionManager = new MyMediaSessionManager(mediaSession,mediaPlayerUSB);
        //设置token后会触发MediaBrowserCompat.ConnectionCallback的回调方法
        //表示MediaBrowser与MediaBrowserService连接成功
        setSessionToken(mediaSession.getSessionToken());
        Settings.System.getInt(getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 0);
    }

    @Nullable
    @Override
    public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
        MyLog.y(TAG+"clientPackageName:"+clientPackageName+" clientUid:"+clientUid+" rootHints:"+rootHints);
        return new BrowserRoot("/",null);
    }

    @Override
    public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
        MyLog.y(TAG+"parentId:"+parentId+" result:"+result);
        result.sendResult(new ArrayList<>());
    }

    //===========================================startForegroundService=======================================

}
